import { connect } from '@umijs/max'
import log from '@/assets/images/icon-logo.png'
import { changeFavicon, changeTitle } from '@/utils/helper'
import 'animate.css'
import React from 'react'
import LoginWithYunqiao from './components/LoginWithYunqiao'

// import bgImage from './image/login-bg.jpg'

@connect(({ login }) => ({ ...login }))
class Login extends React.Component {
  state = {
    logoPreviewUrl: '',
    bgPreviewUrl: '',
    companyName: '',
    loginName: '',
    caseNumber: '',
    bgFilePath: '',
    logoFilePath: '',
    isK8s: process.env.APP_ENV === 'os' || process.env.APP_ENV === 'sp',
  }

  componentDidMount() {
    // this.outLogin()
    // this.getPortalSite()
    // this.clearSession()
  }

  clearSession = () => {
    sessionStorage.removeItem('defaultWorkSpace')
  }

  getPortalSite = () => {
    this.props.dispatch({
      type: 'login/getPortalSite',
      cb: (data) => {
        const {
          logoPreviewUrl,
          bgPreviewUrl,
          companyName,
          loginName,
          caseNumber,
          bgFilePath,
          logoFilePath,
        } = data?.data || {}
        changeFavicon(logoPreviewUrl || log)
        changeTitle('数据集成引擎')
        this.setState({
          logoPreviewUrl,
          bgPreviewUrl,
          companyName,
          loginName,
          caseNumber,
          bgFilePath,
          logoFilePath,
        })
        const titleInfo = JSON.stringify({ companyName, logoPreviewUrl })
        localStorage.setItem('titleInfo', titleInfo)
      },
    })
  }

  render() {
    const {
      logoPreviewUrl,
      bgPreviewUrl,
      companyName,
      loginName,
      caseNumber,
      isK8s,
      bgFilePath,
      logoFilePath,
    } = this.state
    return (
      <div className="login-box">
        <LoginWithYunqiao />
        {/* <LoginAndRegister
          companyName={companyName}
          logoPreviewUrl={
            isK8s
              ? `${window.suanpan}api/v1/file/getFileForPreview?filePath=${logoFilePath}`
              : logoPreviewUrl
          }
          caseNumber={caseNumber}
        />
        <div className="login-postion animate__animated animate__fadeInRightBig">
          <span className="login-name"> 欢迎登录数据集成引擎 </span>
          <LoginForm />
        </div>
        <div className={styles.disabled} /> */}
      </div>
    )
  }
}

export default Login
